package ru.papergames.battleserver.model.battle.npc;

/**
 * @author Alexander Troshanin
 */
public class NpcCell {

    public final static NpcCell NULL_CELL = new NpcCell(-1, -1);

    private final int x;
    private final int y;

    private NpcBall npcBall;
    private boolean hasObstacle;

    public NpcCell(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public NpcBall getNpcBall() {
        return npcBall;
    }

    void setNpcBall(NpcBall npcBall) {
        this.npcBall = npcBall;
        this.npcBall.setCell(this);
    }

    void removeGameBall() {
        if (npcBall != null) {
            npcBall.setCell(null);
        }
        this.npcBall = null;
    }

    public boolean isHasObstacle() {
        return hasObstacle;
    }

    public void setHasObstacle(boolean hasObstacle) {
        this.hasObstacle = hasObstacle;
    }

    public boolean isCellFree() {
        return !hasObstacle && npcBall == null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        NpcCell npcCell = (NpcCell) o;

        if (x != npcCell.x) return false;
        if (y != npcCell.y) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = x;
        result = 31 * result + y;
        return result;
    }
}
